#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" 
@author:zhangxing 
@file: product_result.py 
@time: 2021/06/26 
"""
from django.conf import settings
import os
import pandas



class ProductResult:
    def __init__(self, product_name):
        self.product_name = product_name
        # self.product_results__dir = os.path.join(settings.PRODUCT_BASE_DIR, self.product_name)
        self.product_dir = os.path.join('E:\\result', self.product_name)
        self.product_result_dir_list = os.listdir(self.product_dir)
        self.result_list_absolute_path = ''

    def get_result_dir_full_path(self, index=-1, reverse=False):
        """
        get result dir
        if index default value -1:the latest dir name
        :param reverse:
        :param index:
        :return:
        """
        self.result_list_absolute_path = [os.path.join(self.product_dir, d) for d in self.product_result_dir_list if
                                          len(self.product_result_dir_list) != 0]
        self.result_list_absolute_path.sort(reverse=reverse)
        if len(self.result_list_absolute_path) == 0:
            return self.result_list_absolute_path
        if index:
            try:
                return self.result_list_absolute_path[index]
            except Exception as e:
                print(e)
        else:
            return self.result_list_absolute_path

    @staticmethod
    def walk(path):
        res = {
            'files': [],
            'dirs': []
        }
        for root, dirs, files in os.walk(path, topdown=False):
            for name in files:
                res['files'].append(os.path.join(root, name))
            for name in dirs:
                res['dirs'].append(os.path.join(root, name))
        return res

    def automation_summary_excel(self):
        excel_name = 'automation_test_summary.xls'



if __name__ == '__main__':
    settings.configure()
    p = ProductResult(product_name='FH0031_AB')
    p.get_result_dir_full_path()
    print(p.result_list_absolute_path)
